package com.jeedroid.serviceImpl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.jeedroid.model.User;
import com.jeedroid.model.UserLoginLog;
import com.jeedroid.service.UserService;

public class UserServiceImpl implements UserService
{
private SessionFactory sessionFactory;

public void setSessionFactory(SessionFactory sessionFactory)
{
	this.sessionFactory = sessionFactory;
}

@Override
public boolean checkUserName(User user)
{
	HibernateTemplate hibernateTemplate = new HibernateTemplate(sessionFactory);
	List passwordList = hibernateTemplate.find("u.password from user u where u.username=?", user.getUsername());
	if(passwordList!=null)
	{
		String password = (String) passwordList.get(0);
		if(password.equals(user.getPassword()))
			return true;
		else
			return false;
	}
	else
	{
	return false;
	}
}

@Override
public void writeLoginLog(UserLoginLog userLoginLog)
{
	HibernateTemplate hibernateTemplate = new HibernateTemplate(sessionFactory);
	hibernateTemplate.save(userLoginLog);
}


}
